import { View } from "../../../../mvc/core/View";
import { LayerManager } from "../../../manager/LayerManager";
import { Cache } from "../../../cache/Cache";
import { SPlayerItem } from "../../../../../Message/Public/SPlayerItem";
import { CopyConfig } from "../../../resource/CopyConfig";
import { CopyType } from "../CopyType";
import { ItemData } from "../../../resource/info/ItemData";
import { Global } from "../../../../../com/gengine/global/Global";
import { SixtySkillPropListPanel } from "./SixtySkillPropListPanel";
import { SixtyCopySmeltButton } from "./SixtyCopySmeltButton";
import { SixtyMaterialPanel } from "./SixtyMaterialPanel";
import { SixtyMaterialCanvas } from "./SixtyMaterialCanvas";
type int = number;
//class SixtyCopyView
    
    export  class SixtyCopyView extends View
    {
        constructor()
        {
            super();
            this.layer = LayerManager.uiLayer;
            this.createChildren();
            return;
        }

        protected createChildren(): void
        {
            return;
        }

        public updateItems(): void
        {
            var loc4=null;
            var loc1=Cache.instance.copy.sixtyCopyItems;
            Cache.instance.copy.sixtyMaterialDic = new Map<any, any> /* flash.utils.Dictionary */();
            var loc2=[];
            var loc3=[];
            var loc5=0;
            while (loc5 < loc1.length) 
            {
                loc4 = loc1[loc5] as SPlayerItem;
                if (CopyConfig.instance.isCurrentCopySkill(CopyType.SIXTY_COPY, loc4.itemCode)) 
                {
                    loc2.push(new ItemData(loc4));
                }
                else 
                {
                    loc3.push(new ItemData(loc4));
                    Cache.instance.copy.sixtyMaterialDic[loc4.itemCode] = loc4.itemAmount;
                }
                ++loc5;
            }
            if (this._skillsPanel) 
            {
                this._skillsPanel.updateSkills(loc2);
            }
            if (this._smeltPanel) 
            {
                this._smeltPanel.updateMaterials(loc3);
            }
            if (this._materialCan && Cache.instance.copy.sixtyInWhichFloor() == 1) 
            {
                this._materialCan.setMaterials(loc3);
            }
            return;
        }

        protected onSmeltPanelMinimize(arg1: Object /* flash.events.Event */): void
        {
            this._smeltPanel.hide();
            return;
        }

        protected onMinimizeBtnClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._smeltPanel && this._smeltPanel.isHide) 
            {
                this._smeltPanel.show();
            }
            else 
            {
                this._smeltPanel.hide();
            }
            return;
        }

        public stageResize(): void
        {
            if (this._skillsPanel) 
            {
                if (this._skillsPanel.x > Global.stage.stageWidth - 470) 
                {
                    this._skillsPanel.x = Global.stage.stageWidth - 470;
                }
                if (this._skillsPanel.y > Global.stage.stageHeight - 100) 
                {
                    this._skillsPanel.y = Global.stage.stageHeight - 100;
                }
            }
            if (this._smeltMinimize && this._smeltMinimize.layer) 
            {
                this._smeltMinimize.x = Global.stage.stageWidth - 360;
                this._smeltMinimize.y = 140;
            }
            if (this._materialCan) 
            {
                if (this._materialCan.x > Global.stage.stageWidth - 140) 
                {
                    this._skillsPanel.x = Global.stage.stageWidth - 140;
                }
                if (this._materialCan.y > Global.stage.stageHeight - 120) 
                {
                    this._skillsPanel.y = Global.stage.stageHeight - 120;
                }
            }
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            super.show();
            this.updateView();
            return;
        }

        public /* override */ hide(): void
        {
            super.hide();
            if (this._smeltPanel) 
            {
                this._smeltPanel.hide();
            }
            if (this._smeltMinimize) 
            {
                this._smeltMinimize.hide();
            }
            if (this._skillsPanel && this._skillsPanel.visible) 
            {
                this._skillsPanel.visible = false;
            }
            return;
        }

        public updateView(): void
        {
            var loc1=Cache.instance.copy.sixtyInWhichFloor();
            if (loc1 != 1) 
            {
                if (loc1 == 2) 
                {
                    if (!this._skillsPanel) 
                    {
                        this._skillsPanel = new SixtySkillPropListPanel();
                        this._skillsPanel.x = Global.stage.stageWidth / 2 - 235;
                        this._skillsPanel.y = Global.stage.stageHeight - 150;
                        this.addChild(this._skillsPanel);
                    }
                    this._skillsPanel.visible = true;
                    if (!this._smeltMinimize) 
                    {
                        this._smeltMinimize = new SixtyCopySmeltButton();
                        this._smeltMinimize.addEventListener(flash.events.MouseEvent.CLICK, this.onMinimizeBtnClick);
                    }
                    this._smeltMinimize.show();
                    this.stageResize();
                    if (!this._smeltPanel) 
                    {
                        this._smeltPanel = new SixtyMaterialPanel();
                        this._smeltPanel.addEventListener(SixtyMaterialPanel.MATERIALPANEL_MINIMIZE, this.onSmeltPanelMinimize);
                    }
                    this._smeltPanel.show();
                    this.updateItems();
                    if (this._materialCan && this._materialCan.visible) 
                    {
                        this._materialCan.visible = false;
                        this._materialCan.setMaterials([]);
                    }
                }
            }
            else 
            {
                if (!this._materialCan) 
                {
                    this._materialCan = new SixtyMaterialCanvas();
                    this._materialCan.x = Global.stage.stageWidth - 600;
                    this._materialCan.y = 0;
                    this.addChild(this._materialCan);
                }
                this.updateItems();
                this._materialCan.visible = true;
                if (this._skillsPanel && this._skillsPanel.visible) 
                {
                    this._skillsPanel.visible = false;
                }
                if (this._smeltPanel && !this._smeltPanel.isHide) 
                {
                    this._smeltPanel.hide();
                }
                if (this._smeltMinimize && !this._smeltMinimize.isHide) 
                {
                    this._smeltMinimize.hide();
                }
            }
            return;
        }

        public getSkillPropPointByCode(arg1: int): Object /* flash.geom.Point */
        {
            if (this._skillsPanel) 
            {
                return this._skillsPanel.getSkillPropPointByCode(arg1);
            }
            return new Object /* flash.geom.Point */();
        }

        protected /* var */_smeltMinimize: SixtyCopySmeltButton;

        protected /* var */_skillsPanel: SixtySkillPropListPanel;

        protected /* var */_materialCan: SixtyMaterialCanvas;

        protected /* var */_smeltPanel: SixtyMaterialPanel;
    }
